<?php

namespace Modules\SmallApi\Http\Controllers;

use HiCommon\Model\Admins;
use HiCommon\Model\Banner;
use HiCommon\Model\OrderPay;
use HiCommon\Model\ShopUser;
use HiCommon\Model\ViewFinanceOrderPay;
use HiCommon\MongodbModel\MongoLaravelLog;
use HiCommon\Repository\OrderCheckpointRepository;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Schema;

error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE);
class SmallApiController extends BaseController
{
    /**
     * Display a listing of the resource.
     * @return Response
     */
    public function index()
    {

        dd('ok');


        /*数据库初始化*/
//        $this->init_table();

        /*创建视图*/
//        $this->init_create_view();

//        error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE);

//        $s_table = 'view_finance_order_refund';
        $arr_data_table = [
          'agreement',
          'agreement_cate',
//          'entrust_admin_role_user',
//          'entrust_admin_roles',
//          'entrust_shop_permission_role',
//          'entrust_shop_permissions',
//          'entrust_shop_role_user',
//          'entrust_shop_roles',
        ];
        foreach ($arr_data_table as $s_table)
        {
            make_one_table_model_file($s_table);
            make_one_table_repository_file($s_table);
        }

//        make_one_table_service_file($s_table);
        dd($s_table);

        dd(MongoLaravelLog::get()->toArray());


//        shiwu_start();
////        $res = AutoScheduleService::api_auto_cancle_appointment();
//        $res = AutoScheduleService::api_auto_apprise_appointment_order();
//        shiwu_end($res);
//        dd($res);
//        dd($res);

//        make_one_table_repository_file('order_checkpoint_vehicle_helpdriving');
//        make_one_table_model_file('platform_business_agreement');
//        $a = '201909191751626';

        dd('smallapi');
        return view('smallapi::index');
    }

    public function  init_create_view(){
        $this->view_table_finance_coupon_create();
        $this->view_table_order_pay_create();
        $this->view_table_other();
    }


    /**
     * Show the form for creating a new resource.
     * @return Response
     */
    public function create()
    {
        return view('smallapi::create');
    }

    /**
     * Store a newly created resource in storage.
     * @param  Request $request
     * @return Response
     */
    public function store(Request $request)
    {
    }

    /**
     * Show the specified resource.
     * @return Response
     */
    public function show()
    {
        return view('smallapi::show');
    }

    /**
     * Show the form for editing the specified resource.
     * @return Response
     */
    public function edit()
    {
        return view('smallapi::edit');
    }

    /**
     * Update the specified resource in storage.
     * @param  Request $request
     * @return Response
     */
    public function update(Request $request)
    {
    }

    /**
     * Remove the specified resource from storage.
     * @return Response
     */
    public function destroy()
    {

    }

    public function view_finance_coupon_base_sql(){

        $sql = "
SELECT
	`cu`.`id` AS `id`,
	`pay`.`order_sn` AS `order_sn`,
	`cu`.`user_id` AS `user_id`,
	`cu`.`coupon_id` AS `coupon_id`,
	`c`.`pid` AS `coupon_cate`,
	ifnull(`c`.`repairstore_id`,0) AS `provide_shop_id`,
	ifnull(`c`.`subsidy`,0) AS `subsidy_rate`,
	`cu`.`use_type` AS `use_type`,
	`cu`.`status` AS `status`,
	ifnull(`cu`.`repairstore_id`,0) AS `shop_id`,
	ifnull(`cu`.`is_settle`,2) AS `is_settle`,
	IF((`c`.`pid`= '1'),1,ifnull(`pay`.`is_finish`,2)) AS `is_finish`,
  ifnull(`pay`.`user_coupon_id`,0) AS `user_coupon_id`,
  IF((`c`.`pid`= '1'),1,ifnull(`pay`.`total_fee`,0.00)) AS `total_fee`,
  IF((`c`.`pid`= '1'),0,ifnull(`pay`.`total_refund_fee`,0.00)) AS `total_refund_fee`,
  IF((`c`.`pid`= '1'),(`c`.`price_all`),ifnull(`pay`.`coupon_price`,0.00)) AS `coupon_price`,
  `cu`.`created_at` AS `created_at`,
	`cu`.`updated_at` AS `updated_at`,
	`cu`.`deleted_at` AS `deleted_at`
FROM 
	`car_coupon_grant_detail` `cu`
	LEFT JOIN
	`car_coupons` `c` ON `c`.`id`=`cu`.`coupon_id`
	LEFT JOIN
	`car_view_finance_order_pay` `pay` ON `cu`.`id`=`pay`.`user_coupon_id`
	where `c`.`repairstore_id` = 1 and `cu`.`status` = 2
	";
//  IF(`c`.`pid`==1,ifnull(`pay`.`coupon_price`,0.00),ifnull(`pay`.`coupon_price`,0.00))  AS `coupon_price`
        return $sql;
    }

    public function view_finance_coupon_sql(){
        $sql = "
SELECT 
*,
`fcb`.`coupon_price`*`fcb`.`subsidy_rate`*(`fcb`.`total_fee`-`fcb`.`total_refund_fee`)/(100*`fcb`.`total_fee`) as `settle_money`  
FROM `car_view_finance_coupon_base` as fcb
";
        return $sql;

    }

    public function view_pay_sql_dljy(){
        $sql = "SELECT
	`pay`.`id` AS `id`,
	`pay`.`order_sn` AS `order_sn`,
	`pay`.`pay_time` AS `pay_time`,
	`pay`.`pay_fee` AS `pay_fee`,
	`pay`.`pay_type` AS `pay_type`,
	`pay`.`order_type` AS `order_type`,
	`pay`.`created_at` AS `created_at`,
	`pay`.`updated_at` AS `updated_at`,
	`pay`.`deleted_at` AS `deleted_at`,
	`order`.`user_id` AS `user_id`,
	`order`.`shop_id` AS `shop_id`,
	`order`.`is_finish` AS `is_finish`,
	`order`.`coupon_price` AS `coupon_price`,
	`order`.`user_coupons_id` AS `user_coupon_id`,
	`pay`.`is_settle` AS `is_settle`,
	`pay`.`total_fee` AS `total_fee` ,
	SUM( `refund`.`refund_fee` ) AS `total_refund_fee` 
FROM
	`car_order_pay` `pay`  
LEFT JOIN `car_road_rescue_order` `order` ON `pay`.`order_sn` = `order`.`order_sn`
LEFT JOIN `car_order_pay_refund` `refund` ON `pay`.`order_sn` = `refund`.`out_trade_no`
WHERE
(`pay`.`order_type` = 'dljy' ) 
GROUP BY `pay`.`id`";

        return $sql;
    }

    public function view_pay_sql_njyy(){
        $sql = "SELECT
	`pay`.`id` AS `id`,
	`pay`.`order_sn` AS `order_sn`,
	`pay`.`pay_time` AS `pay_time`,
	`pay`.`pay_fee` AS `pay_fee`,
	`pay`.`pay_type` AS `pay_type`,
	`pay`.`order_type` AS `order_type`,
	`pay`.`created_at` AS `created_at`,
	`pay`.`updated_at` AS `updated_at`,
	`pay`.`deleted_at` AS `deleted_at`,
  `order`.`user_id` AS `user_id`,
	`order`.`shop_id` AS `shop_id`,
  `order`.`is_finish` AS `is_finish`,
  `order`.`coupon_price` AS `coupon_price`,
  `order`.`user_coupons_id` AS `user_coupon_id`,
	`pay`.`is_settle` AS `is_settle`,
	`pay`.`total_fee` AS `total_fee` ,
	SUM( `refund`.`refund_fee` ) AS `total_refund_fee` 
FROM
	`car_order_pay` `pay`  
LEFT JOIN `car_order_checkpoint` `order` ON `pay`.`order_sn` = `order`.`order_sn`
LEFT JOIN `car_order_pay_refund` `refund` ON `pay`.`order_sn` = `refund`.`out_trade_no`
WHERE
(`pay`.`order_type` = 'njyy' ) 
GROUP BY `pay`.`id`";
        return $sql;

    }

    public function view_pay_sql_ptshp(){
        $sql = "SELECT
	`pay`.`id` AS `id`,
	`pay`.`order_sn` AS `order_sn`,
	`pay`.`pay_time` AS `pay_time`,
	`pay`.`pay_fee` AS `pay_fee`,
	`pay`.`pay_type` AS `pay_type`,
	`pay`.`order_type` AS `order_type`,
	`pay`.`created_at` AS `created_at`,
	`pay`.`updated_at` AS `updated_at`,
	`pay`.`deleted_at` AS `deleted_at`,
  `order`.`user_id` AS `user_id`,
	`order`.`shop_id` AS `shop_id`,
  `order`.`is_finish` AS `is_finish`,
  `order`.`coupon_price` AS `coupon_price`,
  `order`.`user_coupons_id` AS `user_coupon_id`,
	`pay`.`is_settle` AS `is_settle`,
	`pay`.`total_fee` AS `total_fee` ,
	SUM( `refund`.`refund_fee` ) AS `total_refund_fee` 
FROM
	`car_order_pay` `pay`  
LEFT JOIN `car_store_order` `order` ON `pay`.`order_sn` = `order`.`order_no`
LEFT JOIN `car_order_pay_refund` `refund` ON `pay`.`order_sn` = `refund`.`out_trade_no`
WHERE
(`pay`.`order_type` = 'ptshp' ) 
GROUP BY `pay`.`id`";
        return $sql;

    }

    public function view_pay_sql_wxby(){
        $sql = "SELECT
	`pay`.`id` AS `id`,
	`pay`.`order_sn` AS `order_sn`,
	`pay`.`pay_time` AS `pay_time`,
	`pay`.`pay_fee` AS `pay_fee`,
	`pay`.`pay_type` AS `pay_type`,
	`pay`.`order_type` AS `order_type`,
	`pay`.`created_at` AS `created_at`,
	`pay`.`updated_at` AS `updated_at`,
	`pay`.`deleted_at` AS `deleted_at`,
  `order`.`user_id` AS `user_id`,
	`order`.`shop_id` AS `shop_id`,
  `order`.`is_finish` AS `is_finish`,
  `order`.`coupon_price` AS `coupon_price`,
  `order`.`user_coupons_id` AS `user_coupon_id`,
	`pay`.`is_settle` AS `is_settle`,
	`pay`.`total_fee` AS `total_fee` ,
	SUM( `refund`.`refund_fee` ) AS `total_refund_fee` 
FROM
	`car_order_pay` `pay`  
LEFT JOIN `car_order_repairstore` `order` ON `pay`.`order_sn` = `order`.`order_number`
LEFT JOIN `car_order_pay_refund` `refund` ON `pay`.`order_sn` = `refund`.`out_trade_no`
WHERE
(`pay`.`order_type` = 'wxby' ) 
GROUP BY `pay`.`id`";
        return $sql;

    }

    public function view_pay_sql_wxfw(){
        $sql = "SELECT
	`pay`.`id` AS `id`,
	`pay`.`order_sn` AS `order_sn`,
	`pay`.`pay_time` AS `pay_time`,
	`pay`.`pay_fee` AS `pay_fee`,
	`pay`.`pay_type` AS `pay_type`,
	`pay`.`order_type` AS `order_type`,
	`pay`.`created_at` AS `created_at`,
	`pay`.`updated_at` AS `updated_at`,
	`pay`.`deleted_at` AS `deleted_at`,
  `order`.`user_id` AS `user_id`,
	`order`.`shop_id` AS `shop_id`,
  `order`.`is_finish` AS `is_finish`,
  `order`.`coupon_price` AS `coupon_price`,
  `order`.`user_coupons_id` AS `user_coupon_id`,
	`pay`.`is_settle` AS `is_settle`,
	`pay`.`total_fee` AS `total_fee` ,
	SUM( `refund`.`refund_fee` ) AS `total_refund_fee` 
FROM
	`car_order_pay` `pay`  
LEFT JOIN `car_order_repairstore` `order` ON `pay`.`order_sn` = `order`.`order_number`
LEFT JOIN `car_order_pay_refund` `refund` ON `pay`.`order_sn` = `refund`.`out_trade_no`
WHERE
(`pay`.`order_type` = 'wxfw' ) 
GROUP BY `pay`.`id`";
        return $sql;

    }

    public function view_pay_sql_order_pay(){
        $sql = "SELECT * FROM `car_view_finance_order_pay_dljy` `pay`
UNION SELECT * FROM `car_view_finance_order_pay_njyy` `pay`
UNION SELECT * FROM `car_view_finance_order_pay_ptshp` `pay`
UNION SELECT * FROM `car_view_finance_order_pay_wxby` `pay`
UNION SELECT * FROM `car_view_finance_order_pay_wxfw` `pay`";
        return $sql;

    }

    public function view_sql_finance_order_refund(){
        $sql = "SELECT
	`refund`.`id` AS `id`,
	`refund`.`order_sn` AS `order_sn`,
	`refund`.`out_trade_no` AS `out_trade_no`,
	`refund`.`out_refund_no` AS `out_refund_no`,
	`refund`.`refund_fee` AS `refund_fee`,
	`refund`.`total_fee` AS `total_fee`,
	`refund`.`type` AS `type`,
	`refund`.`created_at` AS `created_at`,
	`refund`.`updated_at` AS `updated_at`,
	`refund`.`deleted_at` AS `deleted_at`,
	`pay`.`shop_id` AS `shop_id`,
	`pay`.`pay_type` AS `pay_type`,
	`pay`.`order_type` AS `order_type`,
	`pay`.`user_id` AS `user_id` 
FROM
	( `car_order_pay_refund` `refund` JOIN `car_view_finance_order_pay` `pay` ) 
WHERE
	(
	`refund`.`out_trade_no` = `pay`.`order_sn`)";
        return $sql;

    }

    public function view_sql_shop_coupon_grant_detail(){
        $sql = "SELECT
	`cpd`.`id` AS `id`,
	`cpd`.`user_id` AS `user_id`,
	`cpd`.`coupon_id` AS `coupon_id`,
	`cpd`.`pid` AS `pid`,
	`cpd`.`over_at` AS `over_at`,
	`cpd`.`ticket_num` AS `ticket_num`,
	`cpd`.`msg` AS `msg`,
	`cpd`.`integral` AS `integral`,
	`cpd`.`use_type` AS `use_type`,
	`cpd`.`status` AS `status`,
	`cpd`.`created_at` AS `created_at`,
	`cpd`.`updated_at` AS `updated_at`,
	`cpd`.`deleted_at` AS `deleted_at`,
	`cpd`.`repairstore_id` AS `repairstore_id`,
	`cpd`.`type` AS `type`,
	`cpd`.`use_msg` AS `use_msg`,
	`cpd`.`user_level` AS `user_level`,
	`cpd`.`equities` AS `equities`,
	`s`.`id` AS `shop_id` 
FROM
	(( `car_coupon_grant_detail` `cpd` JOIN `car_shop` `s` ) JOIN `car_coupons` ) 
WHERE
	((
			`cpd`.`coupon_id` = `car_coupons`.`id` 
		) 
	AND ( `car_coupons`.`repairstore_id` = `s`.`id` ))";
        return $sql;

    }

    public function view_sql_simple_vehicle_model(){
        $sql = "SELECT
	`three`.`id` AS `id`,
	`three`.`name` AS `three_name`,
	`three`.`parentid` AS `three_pid`,
	`two`.`id` AS `two_id`,
	`two`.`name` AS `two_name`,
	`two`.`parentid` AS `two_pid`,
	`one`.`id` AS `one_id`,
	`one`.`name` AS `one_name`,
	`one`.`parentid` AS `one_pid`,
	`base`.`id` AS `base_id`,
	`base`.`name` AS `name`,
	`base`.`parentid` AS `base_pid`,
	`base`.`logo` AS `logo`,
	`three`.`deleted_at` AS `deleted_at` 
FROM
	(((
				`car_vehicle_model` `three`
				LEFT JOIN `car_vehicle_model` `two` ON ((
						`three`.`parentid` = `two`.`id` 
					)))
			LEFT JOIN `car_vehicle_model` `one` ON ((
					`two`.`parentid` = `one`.`id` 
				)))
		LEFT JOIN `car_vehicle_model` `base` ON ((
				`one`.`parentid` = `base`.`id` 
			))) 
WHERE
	(
	`three`.`depth` = 4)";
        return $sql;

    }

    /*创建支付相关系列视图*/
    public function view_table_order_pay_create(){
        //支付-道路救援 car_view_finance_order_pay_dljy
        $table_name = 'view_finance_order_pay_dljy';
        $sql = $this->view_pay_sql_dljy();
        wm_create_view_table($table_name,$sql);

        //支付-年检预约单 car_view_finance_order_pay_njyy
        $table_name = 'view_finance_order_pay_njyy';
        $sql = $this->view_pay_sql_njyy();
        wm_create_view_table($table_name,$sql);

        //支付-普通商品 car_view_finance_order_pay_ptshp
        $table_name = 'view_finance_order_pay_ptshp';
        $sql = $this->view_pay_sql_ptshp();
        wm_create_view_table($table_name,$sql);

        //支付-维修保养 car_view_finance_order_pay_wxby
        $table_name = 'view_finance_order_pay_wxby';
        $sql = $this->view_pay_sql_wxby();
        wm_create_view_table($table_name,$sql);

        //支付-维修服务 car_view_finance_order_pay_wxfw
        $table_name = 'view_finance_order_pay_wxfw';
        $sql = $this->view_pay_sql_wxfw();
        wm_create_view_table($table_name,$sql);

        //支付-合并总表 car_view_finance_order_pay
        $table_name = 'view_finance_order_pay';
        $sql = $this->view_pay_sql_order_pay();
        wm_create_view_table($table_name,$sql);

    }

    /*创建优惠券补贴视图*/
    public function view_table_finance_coupon_create(){
        //优惠券补贴 view_finance_coupon_base
        $table_name = 'view_finance_coupon_base';
        $sql = $this->view_finance_coupon_base_sql();
        wm_create_view_table($table_name,$sql);

        //优惠券补贴 view_finance_coupon
        $table_name = 'view_finance_coupon';
        $sql = $this->view_finance_coupon_sql();
        wm_create_view_table($table_name,$sql);

    }

    /*创建优惠券补贴视图*/
    public function view_table_other(){
        $table_name = 'view_finance_order_refund';
        $sql = $this->view_sql_finance_order_refund();
        wm_create_view_table($table_name,$sql);

        $table_name = 'view_shop_coupon_grant_detail';
        $sql = $this->view_sql_shop_coupon_grant_detail();
        wm_create_view_table($table_name,$sql);


        $table_name = 'view_simple_vehicle_model';
        $sql = $this->view_sql_simple_vehicle_model();
        wm_create_view_table($table_name,$sql);

    }

    public function split_admin(){
        error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE);
        $arr_field = ['id','username','password','pass','realname','nickname','sex','phone','openid'];
        $res = Admins::whereIn('type',[2,3])->with(['shop_all'])->get($arr_field)->toarray();
        $arr_data = [];
        foreach ($res as $value)
        {
            $arr_data[] = [
              'shop_id'=>intval($value['shop_all']['id']),
              'is_master'=>1,
              'username'=>$value['username'],
              'phone'=>$value['phone'],
              'password'=>$value['password'],
              'pass'=>$value['pass'],
              'nickname'=>$value['nickname'],
              'realname'=>$value['realname'],
              'openid'=>$value['openid'],
              'sex'=>$value['sex'],
            ];
        }
        $res = ShopUser::insert($arr_data);
        dd($res);
    }

    public function my_test(){

        //关联数组
        $arrFirst = [
          "first_key"  => 1,
          "second_key" => 1,
          "third_key"  => 1,
        ];

        $arrSecond = [
          "first_key"  => 2,
          "second_key" => 2,
          "fourth_key" => 2,
        ];
        $a = $arrFirst+$arrSecond;
        $b = array_merge($arrFirst,$arrSecond);
        $c = array_merge_recursive($arrFirst,$arrSecond);
        dump('关联数组');
        dump($a);
        dump($b);
        dump($c);

        //索引数组
        $arrFirst = [
         2=>'a',
         'b',//键名3
         'c'//键名4
        ];

        $arrSecond = [
          'd',//键名0
          2=>'e',
          'f'//键名3
        ];
        $a = $arrFirst+$arrSecond;
        $b = array_merge($arrFirst,$arrSecond);
        $c = array_merge_recursive($arrFirst,$arrSecond);
        dump('索引数组');
        dump($a);
        dump($b);
        dump($c);

        //混合数组
        $arrFirst = [
          111 => 1,
          "second_key" => 1,
          "third_key"  => 1,
        ];

        $arrSecond = [
          "second_key" => 2,
          111  => 2,
          "fourth_key" => 2,
          'ok'//键名112
        ];
        $a = $arrFirst+$arrSecond;
        $b = array_merge($arrFirst,$arrSecond);
        $c = array_merge_recursive($arrFirst,$arrSecond);
        dump('混合数组');
        dump($a);
        dump($b);
        dump($c);

        dd('数组合并');
    }

    public function create_vehicle_model_file(){
        $arr_table = [
          'vehicle_model',
          'vehicle_model_aircondrefrigerator',
          'vehicle_model_basic',
          'vehicle_model_body',
          'vehicle_model_chassisbrake',
          'vehicle_model_doormirror',
          'vehicle_model_drivingauxiliary',
          'vehicle_model_engine',
          'vehicle_model_entcom',
          'vehicle_model_gearbox',
          'vehicle_model_internalconfig',
          'vehicle_model_light',
          'vehicle_model_safe',
          'vehicle_model_seat',
          'vehicle_model_wheel',
        ];
        collect($arr_table)->each(function($value,$key){
            make_one_table_model_file($value);
            make_one_table_repository_file($value);
        });
        dd('ok88');
    }


    public function create_tables(){


        dd('ok');

        $a = json_decode($this->json_data(),true)['result'];
        collect($a)->each(function($value,$key){
            if(is_array($value)){
                $s_table = 'vehicle_model_'.$key;
                if(!Schema::hasTable($s_table)){
                    Schema::create($s_table, function (Blueprint $table)use ($value) {
//                        $table->engine = 'InnoDB';
                        $table->increments('vehicle_model_id')->comment('vehicle_model表id');

                        collect($value)->each(function($vv,$kk)use ($table){
                            $table->string($kk,50)->default('');
                        });

                        $table->string('extend',1);
                        $table->timestamp('created_at');
                        $table->timestamp('updated_at')->nullable();
                        $table->timestamp('deleted_at')->nullable();
                    });
                }

            }

        });

    }

    /*数据库初始化*/
    public function init_table(){

        /*结算*/
        DB::delete('truncate car_account_settlement');
        DB::delete('truncate car_account_settlement_coupon');
        DB::delete('truncate car_account_settlement_order');

        /*活动*/
        DB::delete('truncate car_activity');
        DB::delete('truncate car_activity_extend');
        DB::delete('truncate car_activity_goods_extend');
        DB::delete('truncate car_activity_push');

        /*管理员*/
        //重置管理用户 只保留id为1的admin超级管理员
        DB::delete('truncate car_admins');
        $s_pass = 'wu555662';
        $arr_data = [
          'id'=>1,
//          'type'=>1,
          'username'=>'信达养车',
          'phone'=>'10000000000',
          'password'=>Hash::make($s_pass),
          'pass'=>$s_pass,
        ];
        Admins::create($arr_data);

        /*banner*/
        DB::delete('truncate car_banner');
        $arr_data = [
          [
            'type'=>1,
            'title'=>'首页banner1',
            'img'=>'jinchen/file/2019-09/27/190927052334_5d8dd516c2b7e.png',
            'link_url'=>'#',
          ],
          [
            'type'=>1,
            'title'=>'首页banner2',
            'img'=>'jinchen/file/2019-10/12/191012104838_5da13f062fce7.png',
            'link_url'=>'#',
          ],
          [
            'type'=>1,
            'title'=>'首页banner3',
            'img'=>'jinchen/file/2019-10/12/191012104904_5da13f208ee6d.png',
            'link_url'=>'#',
          ],

          [
            'type'=>5,
            'title'=>'商户端引导页1',
            'img'=>'jinchen/file/2019-10/12/191012104838_5da13f062fce7.png',
            'link_url'=>'#',
          ],
          [
            'type'=>5,
            'title'=>'商户端引导页2',
            'img'=>'jinchen/file/2019-10/12/191012104904_5da13f208ee6d.png',
            'link_url'=>'#',
          ],
        ];
        Banner::insert($arr_data);

        /*年检预约设置*/
        DB::delete('truncate car_checkpoint_make_date');
        DB::delete('truncate car_checkpoint_service_type');

        /*优惠券*/
        DB::delete('truncate car_coupon_grant_detail');

        /*发现*/
        DB::delete('truncate car_discover');
        DB::delete('truncate car_discover_apprise');
        DB::delete('truncate car_discover_zan');

        /*用户权限*/
        DB::delete('truncate car_entrust_permission_role');
        DB::delete('truncate car_entrust_role_user');
        DB::delete('truncate car_entrust_roles');




        DB::delete('truncate car_feedback');
        DB::delete('truncate car_goods');
//        DB::delete('truncate car_goods_cate');
        DB::delete('truncate car_goods_img');
        DB::delete('truncate car_goods_product');
//        DB::delete('truncate car_goods_sale_tag');
        DB::delete('truncate car_goods_sale_tag_relation');
        DB::delete('truncate car_goods_specs');
        DB::delete('truncate car_goods_specs_cate');
        DB::delete('truncate car_goods_specs_cate_goods');
//        DB::delete('truncate car_handbook');
//        DB::delete('truncate car_handbook_upkeep_type');
//        DB::delete('truncate car_insurance_company');
//        DB::delete('truncate car_insurance_company_seed');

        DB::delete('truncate car_invoice');
        DB::delete('truncate car_invoice_apply');
        DB::delete('truncate car_invoice_apply_extend');
        DB::delete('truncate car_maintain_config');
        DB::delete('truncate car_maintain_shop');
        DB::delete('truncate car_maintain_shop_goods');
        DB::delete('truncate car_maintain_vehicle_model');

        DB::delete('truncate car_manual');
        DB::delete('truncate car_message');
//        DB::delete('truncate car_notice');

        DB::delete('truncate car_order_checkpoint');
        DB::delete('truncate car_order_checkpoint_refund');
        DB::delete('truncate car_order_checkpoint_vehicle');
        DB::delete('truncate car_order_checkpoint_vehicle_helpdriving');
        DB::delete('truncate car_order_mall');
        DB::delete('truncate car_order_pay');
        DB::delete('truncate car_order_pay_json');
        DB::delete('truncate car_order_pay_refund');

        DB::delete('truncate car_order_repairstore');
        DB::delete('truncate car_order_repairstore_goods');
//        DB::delete('truncate car_order_repairstore_apprise');
        DB::delete('truncate car_platform_business_agreement');
        DB::delete('truncate car_protocol');


        DB::delete('truncate car_repairstore_goods');
        DB::delete('truncate car_repairstore_goods_img');
//        DB::delete('truncate car_repairstore_type');


        DB::delete('truncate car_road_rescue');
        DB::delete('truncate car_road_rescue_config');
        DB::delete('truncate car_road_rescue_config_extend');
        DB::delete('truncate car_road_rescue_order');


//        DB::delete('truncate car_shop');
        DB::delete('truncate car_shop_account');
        DB::delete('truncate car_shop_account_log');
        DB::delete('truncate car_shop_checkpoint_service_specs');
        DB::delete('truncate car_shop_img');
        DB::delete('truncate car_shop_master');
        DB::delete('truncate car_shop_modify');
        DB::delete('truncate car_shop_modify_img');
        DB::delete('truncate car_shop_server_type');
        DB::delete('truncate car_shop_user');


        DB::delete('truncate car_store_car');
        DB::delete('truncate car_store_order');
        DB::delete('truncate car_store_order_goods');
        DB::delete('truncate car_store_order_refund');

        DB::delete('truncate car_upkeep');
        DB::delete('truncate car_upkeep_type');

        /*用户*/
        DB::delete('truncate car_user_address');
        DB::delete('truncate car_user_collect');
        DB::delete('truncate car_user_invite');
        DB::delete('truncate car_users');
        DB::delete('truncate car_users_apprise');
        DB::delete('truncate car_users_company');
        DB::delete('truncate car_users_integral');

        DB::delete('truncate car_users_jpush_set');
        DB::delete('truncate car_users_vehicle');
        DB::delete('truncate car_users_vehicle_insurance');


    }

    public function clear_table_for_all_order(){
        /*商品+ 保养、维修*/
        DB::delete('truncate car_store_order');
        DB::delete('truncate car_store_order_goods');
        DB::delete('truncate car_store_order_refund');
        DB::delete('truncate car_store_order_refund_goods');
        DB::delete('truncate car_order_repairstore');
        DB::delete('truncate car_order_repairstore_goods');
        DB::delete('truncate car_order_mall');

        /*道路救援*/
        DB::delete('truncate car_road_rescue_order');

        /*年检预约*/
        DB::delete('truncate car_order_checkpoint');
        DB::delete('truncate car_order_checkpoint_refund');
        DB::delete('truncate car_order_checkpoint_vehicle');
        DB::delete('truncate car_order_checkpoint_vehicle_helpdriving');

        /*支付及退款表*/
        DB::delete('truncate car_order_pay');
        DB::delete('truncate car_order_pay_json');
        DB::delete('truncate car_order_pay_refund');
    }
}
